Skip to content

feat(inputs.prometheus): Add per-URL statistics on gather cycles#18944

Open
nlgotz wants to merge 5 commits into
influxdata:masterfrom
nlgotz:prom-internal-gather-stats
Open

feat(inputs.prometheus): Add per-URL statistics on gather cycles#18944
nlgotz wants to merge 5 commits into
influxdata:masterfrom
nlgotz:prom-internal-gather-stats

Conversation

@nlgotz
Copy link
Copy Markdown

@nlgotz nlgotz commented May 19, 2026

Summary

Adds 2 new internal metrics to the Prometheus input plugin.

  • connection_status sets the value to either 0 (connection failed) or 1 (connection succeeded).
  • gathers_total which has a status tag of either success or failure that increments on each gather.

Checklist

Related issues

resolves #18943

@telegraf-tiger
Copy link
Copy Markdown
Contributor

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@telegraf-tiger telegraf-tiger Bot added area/prometheus feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels May 19, 2026
@nlgotz
Copy link
Copy Markdown
Author

nlgotz commented May 19, 2026

!signed-cla

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @nlgotz! Two comments from my side...

Comment thread plugins/inputs/prometheus/prometheus.go Outdated
Comment thread plugins/inputs/prometheus/prometheus.go Outdated
@srebhan srebhan self-assigned this May 20, 2026
@nlgotz nlgotz requested a review from srebhan May 22, 2026 13:42
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nlgotz!

@srebhan srebhan changed the title feat(inputs.prometheus): Add new internal stats on Prometheus gathers feat(inputs.prometheus): Add statistics on gather cycles May 27, 2026
@srebhan srebhan changed the title feat(inputs.prometheus): Add statistics on gather cycles feat(inputs.prometheus): Add per-URL statistics on gather cycles May 27, 2026
@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label May 27, 2026
@srebhan srebhan assigned skartikey and unassigned srebhan May 27, 2026
Copy link
Copy Markdown
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nlgotz, please take a look at the comments.

Comment thread plugins/inputs/prometheus/prometheus.go Outdated
Comment thread plugins/inputs/prometheus/prometheus.go Outdated
Comment thread plugins/inputs/prometheus/prometheus.go Outdated
@telegraf-tiger
Copy link
Copy Markdown
Contributor

@skartikey
Copy link
Copy Markdown
Contributor

The race, the nil-guard, and the redundant struct maps are all addressed, thanks. A few items are still open in the reworked gatherURL:

  1. Six early-return error paths (L478-529: http.NewRequest, BearerToken file read, BearerTokenString.Get, Username.Get, Password.Get) skip the stat updates entirely, so gathers_total{status="failure"} undercounts those failures.

  2. connection_status is inconsistent across "connected but no metrics" outcomes:

    • content-length-exceeded (L585-590) sets it to 0
    • parse error (L624-628) leaves it at 1
  3. The new stats have no test coverage. The test diff only wires up Statistics: selfstat.NewCollector(nil) to keep existing tests compiling; nothing asserts connectStat / successStat / failureStat values.

Both 1 and 2 fall out naturally if you account gathers_total once in the Gather goroutine from the err returned by gatherURL (and handle the content-length skip explicitly), which also drops the three stat params from gatherURL’s signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/prometheus feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[inputs.prometheus] Connection Status internal metric

3 participants